#pragma once
#include "IImage.h"
//#include "ITexture.h"

BEGIN_WARE

class ITexture;

class CImage : public IImage
{
public:
	CImage( ITexture* pTex, SIntRect& rc ) : m_pTexture( pTex ), m_Rect(rc)
	{
		int32 nWidth = m_pTexture->GetWidth();
		int32 nHeight = m_pTexture->GetHeight();

		m_vU[0] = ( rc.left / static_cast<float32>(nWidth) );
		m_vU[1] = ( ( rc.right + 1 ) / static_cast<float32>(nWidth) );

		m_vV[0] = ( rc.top / static_cast<float32>(nHeight) );
		m_vV[1] = ( ( rc.bottom + 1 ) / static_cast<float32>(nHeight) );
	}

	virtual ITexture*		GetTexture()			{ return m_pTexture; }

	virtual void			GetU( CVector2& u )		{ u = m_vU; }
	virtual void			GetV( CVector2& v )		{ v = m_vV; }

	virtual VBOOL			SaveToFile( const VCHAR* szSaveFileName, ITexture::ETextureFileType eFileType = ITexture::TFP_PNG, EWareFormat eFormat = WARE_FMT_A8R8G8B8 );

	int32					GetWidth()				{ return m_Rect.Width(); }
	int32					GetHeight()				{ return m_Rect.Height(); }
	void					GetRect( SIntRect& rc )	{ rc = m_Rect; }


private:

	ITexture*				m_pTexture;

	SIntRect				m_Rect;
	CVector2				m_vU;
	CVector2				m_vV;
};

END_WARE